<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta content="webkit" name="renderer">
    <meta content="IE=edge,chrome=1" http-equiv="X-UA-Compatible">
    <meta content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0"
          name="viewport">
    <link rel="stylesheet" href="/asset/layui/css/layui.css" media="all">
</head>
<body>

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card-body">
                <div class="layui-form" lay-filter="form">

                    <div class="layui-form-item">
                        <label class="layui-form-label">租户名<span style="color: red">*</span></label>
                        <div class="layui-input-block">
                            <input type="text" class="layui-input" name="name" autocomplete="off" lay-verify="required">
                        </div>
                    </div>

                    <div class="layui-form-item layui-hide">
                        <input type="button" lay-submit lay-filter="save" id="save">
                        <input type="button" lay-submit lay-filter="update" id="update">
                    </div>

                </div>
            </div>
        </div>
    </div>
</div>

<script src="/asset/layui/layui.js"></script>
<script src="/my/fast.js"></script>
<script>

    // 接口地址
    let saveOrUpdate = UPMS_ADDRESS + '/sysTenant/saveOrUpdate';
    let get = UPMS_ADDRESS + '/sysTenant/get';

    layui.use(() => {
        let $ = layui.$;
        let form = layui.form;

        // 监听表单提交--save
        form.on('submit(save)', data => {
            layuiSubmit(saveOrUpdate, data.field, 'table');
        });

        // 更新时为表单赋值
        let id = oneValue();
        if (id) {
            $.get(get, {id: id}, rs => {
                if (rs.success) {
                    let data = rs.data;
                    // 为表单赋值
                    form.val('form', data);
                    // 监听表单提交--update
                    form.on('submit(update)', obj => {
                        layuiSubmit(saveOrUpdate, {...data, ...obj.field}, 'table');
                    });
                }
            });
        }

    });
</script>
</body>
</html>
